<%@page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<link href="${apliPath}static/css/default.css" rel="stylesheet"
	type="text/css" />
<link rel="stylesheet" type="text/css"
	href="${apliPath}static/js/themes/metro-solidBlue/easyui.css" />
<link rel="stylesheet" type="text/css"
	href="${apliPath}static/js/themes/icon.css" />
<script type="text/javascript"
	src="${apliPath}static/js/jquery-1.10.2.js"></script>
<script type="text/javascript"
	src="${apliPath}static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${apliPath}static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	$(function() {
		var list = [ {
			"text" : "学士系统日志记录",
			"type" : "factory",
			"state" : "open",
			"operKind" : null,
			"iconCls" : "icon-parent-1",
			"children" : [ {
				"id" : 1,
				"text" : "管理员日志",
				"type" : "dept",
				"checked" : false,
				"operKind" : 1,
				"iconCls" : "icon-parent-1",
				"children" : null
			}, {
				"text" : "角色日志",
				"type" : "dept",
				"operKind" : 2,
				"iconCls" : "icon-parent-1",
				"children" : null
			}, {
				"id" : 1,
				"text" : "其他日志",
				"type" : "dept",
				"operKind" : 1,
				"iconCls" : "icon-parent-1",
				"children" : null
			} ]
		} ];
		$("#logTree").tree({
			data : list
		});
		$("#logTree").tree({
			onClick : function(node) {
				queryLogInfoByType(node.operKind);
			},
			onDblClick : function(node) {
				if (node.state == "closed") {
					$("#logTree").tree("expand", node.target);
				} else {
					$("#logTree").tree("collapse", node.target);
				}
			}

		});
		initialDatebox();
		// 查找id为null的父节点并选择它
		var node = $('#logTree').tree('find', null);
		$('#logTree').tree('select', node.target);
		queryLogInfoByType();
	});
	function queryLogInfoByType(kind) {
		var beginTime = $('#bTime').datebox('getValue') + ' '
				+ $('#bhTime').timespinner('getValue');
		var endTime = $('#eTime').datebox('getValue') + ' '
				+ $('#ehTime').timespinner('getValue');
		$("#manageLogInfo").datagrid({
			title : "日志列表",
			fit : true,
			border : false,
			toolbar : '#toolBar',
			iconCls : 'icon-search',
			url : "${apliPath}logInfo/queryLogInfosByPage",
			queryParams : {
				operType : $('#logTree').tree('getSelected').operKind,
				beginTime : beginTime,
				endTime : endTime,
				content : $('#fuzzyOperContent').textbox('getValue')
			},
			striped : true,
			loadMsg : "数据正在加载中，请稍等...",
			rownumbers : true,
			singleSelect : true,
			columns : [ [ {
				field : "id",
				hidden : true,
			}, {
				title : "操作人标识",
				field : "code",
				width : 100,
				align : "center"
			}, {
				title : "操作时间",
				field : "createDate",
				width : 140,
				align : "center",
				sortable : true,
			}, {
				title : "操作IP",
				field : "requestIP",
				align : "center",
				width : 120,
			}, {
				title : "操作主题",
				field : "operation",
				align : "center",
				width : 140,
			}, {
				title : "操作内容",
				field : "content",
				align : "left",
				width : 600,
			} ] ],
			pagination : true,
			pageSize : 6,
			pageList : [ 3, 6, 9, 12 ],
			sortName : "id",
			sortOrder : "DESC",
			remoteSort : false,
		});
	}
	function exportSysLogExcel() {
		var beginDate = $('#makeDateBegin').datebox('getValue');
		var endDate = $('#makeDateEnd').datebox('getValue');
		var type = $('#listTypeSelect').combobox('getValue');
		var subType = $('#subListTypeSelect').combobox('getValue');
		var transData = new Object();
		transData.beginDate = beginDate;
		transData.endDate = endDate;
		//transData.type = type;
		//transData.subType = subType;
		$.get('${apliPath}logInfo/exportExcel', transData);
	}
</script>
<iframe name="downloadFrame" style="display:none"></iframe>
<div id="toolBar" style="float: right">
	<table>
		<tr>
			<td><a class="easyui-linkbutton"
				href="javascript:inintialExcelConditonWindow()"
				data-options="iconCls:'icon icon-export'">打印</a></td>
			<td><input type="text" id="bTime" /></td>
			<td><input type="text" id="bhTime" /></td>
			<td><input type="text" id="eTime" /></td>
			<td><input type="text" id="ehTime" /></td>
			<td>操作模糊：<input type="text" id="fuzzyOperContent" width="90"
				class="easyui-textbox">
			</td>
			<td><a class="easyui-linkbutton"
				href="javascript:queryLogInfoByType()"
				data-options="iconCls:'icon-search',width:60">查询</a></td>
		</tr>
	</table>
</div>
<div id="exportToExcelConditonWindow"
	data-options="minimizable : false,modal : true,title:'打印条件',maximizable : false,	closable : false,	draggable : false,closed:true,
			resizable : false,collapsible : false"
	class="easyui-window" style="text-align:center;margin:2;">
	<form id="form_exportCondition" method="post">
		<table width="360" border="0" cellpadding="0" cellspacing="0"
			style="font-size:12px; margin:2px;">
			<tr>
				<td height="32" width="80" align="right">时间段：</td>
				<td width="300" colspan="3"><input name="drep.remark"
					style="width: 110" class="easyui-datebox" id="makeDateBegin"
					data-options="editable:false">&nbsp;到&nbsp;<input
					id="makeDateEnd"
					data-options="editable:false,validType:'equaldDate[\'#makeDateBegin\']'"
					class="easyui-datebox" style="width: 110"></td>
			</tr>
			<tr>
				<td height="32" width="80" align="right">导出类型：</td>
				<td width="300" colspan="3"><select id="listTypeSelect"
					style="width: 120px;"></select>&nbsp;&nbsp;&nbsp;<select
					id="subListTypeSelect" style="width: 120px;"></select></td>

			</tr>
			<tr>
				<td height="32" width="80" align="right"></td>
				<td align="left"><a href="javascript:void(0)"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-save',onClick:function(){
								    exportToExcel();
								}">确&nbsp;&nbsp;定</a></td>
				<td height="32"></td>
				<td align="left"><a href="javascript:void(0)"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-redo',onClick:function(){
								   $('#form_exportCondition').form('reset');
								   $('#exportToExcelConditonWindow').window('close');
								}">取&nbsp;&nbsp;消</a></td>
			</tr>
		</table>
	</form>
</div>
<body class="easyui-layout" id="layoutBody">
	<div data-options="region:'west',split:true,border:false"
		style="width:180px; border:2px">
		<br>
		<ul id="logTree" class="easyui-tree"></ul>
	</div>
	<div data-options="region:'center',border:false" style="border:0px;">
		<table id="manageLogInfo">
		</table>
	</div>
</body>
<script type="text/javascript">
	function inintialExcelConditonWindow() {
		$('#subListTypeSelect').combobox({
			data : subListType[0],
			valueField : 'id',
			textField : 'value',
			value : 0
		});
		$('#listTypeSelect').combobox(
				{
					data : listType,
					valueField : 'id',
					textField : 'value',
					value : 0,
					onSelect : function(record) {
						$('#subListTypeSelect').combobox('loadData',
								subListType[record.id]);
						$('#subListTypeSelect').combobox('clear');
					}
				});
		$('#exportToExcelConditonWindow').window('open');
	}
	function initialDatebox() {
		var newDate = new Date();
		var years = newDate.getFullYear();
		var years2 = (new Date(newDate.getTime() - 24 * 60 * 60 * 1000 * 6))
				.getFullYear();
		var month = newDate.getMonth() + 1;
		var month2 = (new Date(newDate.getTime() - 24 * 60 * 60 * 1000 * 6))
				.getMonth() + 1;
		var date = newDate.getDate();
		var date2 = (new Date(newDate.getTime() - 24 * 60 * 60 * 1000 * 6))
				.getDate();
		if (month <= 9) {
			month = "0" + month;
		}
		if (month2 <= 9) {
			month2 = "0" + month2;
		}
		if (date <= 9) {
			date = "0" + date;
		}
		if (date2 <= 9) {
			date2 = "0" + date2;
		}
		var beginDate = years2 + "-" + month2 + "-" + date2;
		var endDate = years + "-" + month + "-" + date;
		$('#bTime').datebox({
			required : true,
			value : beginDate,
			editable : false,
			width : 120
		});
		$('#eTime').datebox({
			required : true,
			value : endDate,
			editable : false,
			width : 120
		});
		$('#bhTime').timespinner({
			required : true,
			showSeconds : true,
			value : '00:00:00',
			min : '00:00:00',
			max : '23:59:59',
			width : 120
		});
		$('#ehTime').timespinner({
			required : true,
			showSeconds : true,
			value : '23:59:59',
			min : '00:00:00',
			max : '23:59:59',
			width : 120
		});
	}
	$.extend($.fn.validatebox.defaults.rules, {
		equaldDate : {
			validator : function(value, param) {
				var d1 = $(param[0]).datetimebox('getValue'); // 获取开始时间
				return value >= d1; // 有效范围为大于开始时间的日期
			},
			message : '结束日期不能早于开始日期!'
		}
	});
	var listType = [ {
		id : 0,
		value : '全部日志 '
	}, {
		id : 1,
		value : '管理员日志'
	}, {
		id : 2,
		value : '角色日志'
	}, {
		id : 3,
		value : '专辑日志'
	} ];
	var subListType = [ [ {
		id : 0,
		value : '全部日志 '
	} ], [ {
		id : 1,
		value : '插入管理员日志'
	}, {
		id : 2,
		value : '更新管理员日志'
	}, {
		id : 3,
		value : '删除管理员日志'
	}, {
		id : 4,
		value : '修改管理员权限'
	} ], [ {
		id : 1,
		value : '插入角色日志'
	}, {
		id : 2,
		value : '删除角色日志'
	}, {
		id : 3,
		value : '修改角色日志'
	} ], [ {
		id : 1,
		value : '插入专辑日志'
	}, {
		id : 2,
		value : '删除专辑日志'
	}, {
		id : 3,
		value : '修改专辑日志'
	} ] ];
	function exportToExcel() {
		var beginDate = $('#makeDateBegin').datebox('getValue');
		var endDate = $('#makeDateEnd').datebox('getValue');
		var type = $('#listTypeSelect').combobox('getValue');
		var subType = $('#subListTypeSelect').combobox('getValue');
		//excelDownload('${apliPath}logInfo/exportExcel?beginTime=' + beginDate
		//	+ '&endTime=' + endDate + '&operType=' + type + '&subOperType='
		//+ subType, 'post', '', ''); // 下载文件
		saveit('${apliPath}logInfo/exportExcel?beginTime=' + beginDate
				+ '&endTime=' + endDate + '&operType=' + type + '&subOperType='
				+ subType);
		$('#exportToExcelConditonWindow').window('close');
	}
	excelDownload = function(url, method, filedir, filename) {
		jQuery(
				'<form action="'
						+ url
						+ '" method="'
						+ (method || 'post')
						+ '">'
						+ '<input type="text" name="filedir" value="' + filedir + '"/>'
						+ // 文件路径
						'<input type="text" name="excelName" value="' + filename + '"/>'
						+ // 文件名称
						'</form>').appendTo('body').submit().remove();
	};
	//下载方式二
	function saveit(src) {
		downloadFrame.document.location = src;
		savepic();
	}
	function savepic() {
		if (downloadFrame.document.readyState == "complete") {
			downloadFrame.document.execCommand("saveas");
		} else {
			window.setTimeout("savepic()", 10);
		}
	}
</script>



